<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ha_model extends CI_Model {

	public function get_list(){
		$this->db->order_by('lv_id','ASC');
		return $this->db->get('ref_level');
	}

	public function get_data($id){
		$this->db->select('a.*,(SELECT COUNT(*) FROM profile_menu b WHERE a.id_main = b.u_menu_id AND b.u_user_id = '.$id.') as checked');
		$this->db->from('ref_menu a');

		return $this->db->get();
	}

	public function do_update($id = false,$param = false){
		if($id){
			$this->db->where('u_user_id',$id);
			$this->db->delete('profile_menu');
			$insert = '';
			
			foreach ($param as $value){
				$this->db->set('u_menu_id',$value);
				$this->db->set('u_user_id',$id);
				$insert = $this->db->insert('profile_menu');
			}

			if($insert) return true;
			else return false;
		}
		return false;
	}

	public function do_delete($id = false){
		if($id){
			$this->db->where('id_main',$id);
			return $this->db->delete('ref_menu');
		}return false;
	}
}